
var app = getApp();
var lru='';
Page({
  data: {
  namei:'',
  sexi:'',
  IDcardi:'',
  time:'',
  tip:'',
  BLYF:'',
  phone:'',
  JKZP:'',
  TP:'',
  TPTF:'',
  HXKN:'',
  record:[],
  fileUrl:''

  },
  //获取输入的姓名
  getNamei(event) {
    console.log('获取输入的用户名', event.detail.value)
    this.setData({
     namei: event.detail.value
    })
    },
  
  //获取输入的身份证号
  getIDcardi(event) {
  // console.log('身份证号', event.detail.value)
  this.setData({
   IDcardi: event.detail.value
  })
  },
  //获取输入的时间
  getTime(event) {
    // console.log('时间', event.detail.value)
    this.setData({
     time: event.detail.value
    })
    },
    asjpx(){
      var that=this
      wx.cloud.database().collection('record').orderBy('time','asc').get({
        success(res){
          console.log(123)
          var record=[]
          var tip='3'
          record=res.data
          console.log(123)
          console.log(record)
          app.globalData.record=record
          that.setData({
            tip:tip,
            record:record
          }
          );
          wx.navigateTo({
            url: '../px/px',
          }
          )
        },
        fail(res) {
          console.log("获取数据失败", res)
         }
      })

    },
    axbpx(){
      var that=this
      wx.cloud.database().collection('record').orderBy('sexi','asc').get({
        success(res){
          console.log(123)
          var record=[]
          var tip='4'
          record=res.data
          console.log(123)
          console.log(record)
          app.globalData.record=record
          that.setData({
            tip:tip,
            record:record
          }
          );
          wx.navigateTo({
            url: '../px/px',
          }
          )
        },
        fail(res) {
          console.log("获取数据失败", res)
         }
      })

    },
    xzcx(){
      var that=this
      var tip='2'
      that.setData({
        tip:tip

    }
      );
      wx.navigateTo({
        url: '../px/px',
      })
    }
    ,
    cx(){
      var that=this
      console.log(this.data.namei)
      let namei=this.data.namei
      let IDcardi=this.data.IDcardi
      let time=this.data.time
      console.log(namei)
      console.log(IDcardi)
      console.log(time)

      wx.cloud.database().collection('record').where({
        namei:namei,
        IDcardi:IDcardi,
        time:time
       }).get({
        success(res) {
         console.log("查询数据成功", res)
         console.log(namei)
         let record = res.data[0]
         app.globalData.record=record
         console.log("record", record)
         console.log(IDcardi)
         console.log(record.IDcardi)
         
          console.log('查询成功')
          wx.showToast({
           title: '查询成功',
          })
          // wx.navigateTo({
          //  url: '../home/home?name=' + user.name,
          // })
       
          var namei=record.namei
          var sexi=record.sexi
          var IDcardi=record.IDcardi
          var phone=record.IDcardi
          var time=record.time
          var BLYF=record.BLYF
          var HXKN=record.HXKN
          var JKZP=record.JKZP
          var TP=record.TP
          var TPTF=record.TPTF
          app.globalData.namei=namei
          app.globalData.sexi=sexi
          app.globalData.IDcardi=IDcardi
          app.globalData.phone=phone
          app.globalData.time=time
          app.globalData.TP=TP
          app.globalData.TPTF=TPTF
          app.globalData.BLYF=BLYF
          app.globalData.HXKN=HXKN
          app.globalData.JKZP=JKZP
          var tip='1'
          console.log(tip)
          console.log(TP)
          that.setData({
            namei:namei,
            sexi:sexi,
            IDcardi:IDcardi,
            phone:phone,
            time:time,
            BLYF:BLYF,
            HXKN:HXKN,
            JKZP:JKZP,
            TP:TP,
            TPTF:TPTF,
            tip:tip

        }
        );
        //保存用户登陆状态
        wx.setStorageSync('record', record)
           wx.navigateTo({
             url: '../px/px',
           })
         
          
        },
        fail(res) {
         console.log("获取数据失败", res)
        }
       })
       
    }
    ,
    getExcelsj: function (contentArr) {
      let that=this;
      var record=app.globalData.record;
      wx.cloud.callFunction({
        name: 'excelexport2',
        data: {
          excelhead: ["姓名", "性别", "身份证号", "手机号码", "监测时间", "监测体温", "体温是否正常", "是否鼻塞流涕咽痛腹泻", "是否呼吸困难", "健康状况总评", ],
          excelbody:record
      
      
        },
        success: function (res) {
          console.log(res.result.fileID);
          console.log(456);
          wx.cloud.getTempFileURL({
            fileList: [res.result.fileID],
            success: res => {
              // get temp file URL
              console.log("文件下载链接", res.fileList[0].tempFileURL)
              that.setData({
                fileUrl: res.fileList[0].tempFileURL,
                
              })
            },
            fail: err => {
              // handle error
            }
          })
        },
        fail: function (res) {
          console.log(res);
          console.log(123);
        }
      })
    },
    getExcelxb: function (contentArr) {
      let that=this;
      var record=app.globalData.record;
      wx.cloud.callFunction({
        name: 'excelexport2',
        data: {
          excelhead: ["姓名", "性别", "身份证号", "手机号码", "监测时间", "监测体温", "体温是否正常", "是否鼻塞流涕咽痛腹泻", "是否呼吸困难", "健康状况总评", ],
          excelbody:record
      
      
        },
        success: function (res) {
          console.log(res.result.fileID);
          console.log(456);
          wx.cloud.getTempFileURL({
            fileList: [res.result.fileID],
            success: res => {
              // get temp file URL
              console.log("文件下载链接", res.fileList[0].tempFileURL)
              that.setData({
                fileUrl: res.fileList[0].tempFileURL,
                
              })
            },
            fail: err => {
              // handle error
            }
          })
        },
        fail: function (res) {
          console.log(res);
          console.log(123);
        }
      })
    },
    getExcelcx: function (contentArr) {
      let that=this
      var namei=app.globalData.namei
      var sexi=app.globalData.sexi
      var IDcardi=app.globalData.IDcardi
      var phone=app.globalData.phone
      var time=app.globalData.time
      var TP=app.globalData.TP
      var TPTF=app.globalData.TPTF
      var BLYF=app.globalData.BLYF
      var HXKN=app.globalData.HXKN
      var JKZP=app.globalData.JKZP
      wx.cloud.callFunction({
        name: 'excelexport2',
        data: {
          excelhead: ["姓名", "性别", "身份证号", "手机号码", "监测时间", "监测体温", "体温是否正常", "是否鼻塞流涕咽痛腹泻", "是否呼吸困难", "健康状况总评", ],
          excelbody:[{'namei':namei,'sexi':sexi,'IDcardi':IDcardi,'phone':phone,'time':time,'TP':TP,'TPTF':TPTF,'BLYF':BLYF,'HXKN':HXKN,'JKZP':JKZP}]
      
      
        },
        success: function (res) {
          console.log(res.result.fileID);
          console.log(456);
          wx.cloud.getTempFileURL({
            fileList: [res.result.fileID],
            success: res => {
              // get temp file URL
              console.log("文件下载链接", res.fileList[0].tempFileURL)
              that.setData({
                fileUrl: res.fileList[0].tempFileURL,
                
              })
            },
            fail: err => {
              // handle error
            }
          })
        },
        fail: function (res) {
          console.log(res);
          console.log(123);
        }
      })
    },
  //点击登陆
  login() {
  let zhanghao = this.data.zhanghao
  let mima = this.data.mima
  console.log('账号', zhanghao, '密码', mima)
  if (zhanghao.length < 4) {
    wx.showToast({
     icon: 'none',
     title: '账号至少4位',
    })
    return
   }
  if (mima.length < 4) {
   wx.showToast({
    icon: 'none',
    title: '密码至少4位',
   })
   return
  }
  
  //登陆
  wx.cloud.database().collection('user').where({
   zhanghao: zhanghao
  }).get({
   success(res) {
    console.log("获取数据成功", res)
    let user = res.data[0]
    console.log("user", user)
    if (mima == user.mima) {
     console.log('登陆成功')
     wx.showToast({
      title: '登陆成功',
     })
     // wx.navigateTo({
     //  url: '../home/home?name=' + user.name,
     // })
  
     app.globalData.type=user.type
     app.globalData.CARD=user.CARD
     app.globalData.name=user.name
     app.globalData.sex=user.sex
     app.globalData.IDcard=user.IDcard
     app.globalData.fileID=user.fileID
     app.globalData.houseID=user.houseID
     app.globalData.ioNumber=user.ioNumber
     console.log(app.globalData.mima);
      wx.switchTab({
        url: '../list/list',
      })
     //保存用户登陆状态
     wx.setStorageSync('user', user)
    } else {
     console.log('登陆失败')
     wx.showToast({
      icon: 'none',
      title: '账号或密码不正确',
     })
    }
   },
   fail(res) {
    console.log("获取数据失败", res)
   }
  })
  
  }
  })